﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
using WebExam.Core.Repository;

namespace WebExam.DataEntities
{

    [Table(Name = "dbo.TX")]
    public partial class TX :Entity
    {

        private decimal _txNum;

        private decimal _examNum;

        private string _txName;

        private int _tl;

        private float _singleScore;

        private float _fullScore;

        private string _bz;

        private int _timeArea;

        private EntitySet<EnPower> _EnPower;

        private EntitySet<STK> _STK;

        private EntityRef<ExamPaper> _ExamPaper;

        public TX()
        {
            this._EnPower = new EntitySet<EnPower>(new Action<EnPower>(this.attach_EnPower), new Action<EnPower>(this.detach_EnPower));
            this._STK = new EntitySet<STK>(new Action<STK>(this.attach_STK), new Action<STK>(this.detach_STK));
            this._ExamPaper = default(EntityRef<ExamPaper>);
        }

        [Column(Storage = "_txNum", AutoSync = AutoSync.OnInsert, DbType = "Decimal(18,0) NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public decimal TXNum
        {
            get
            {
                return this._txNum;
            }
            set
            {
                if ((this._txNum != value))
                {
                    this.SendPropertyChanging("TXNum");
                    this._txNum = value;
                    this.SendPropertyChanged("TXNum",value);
                }
            }
        }

        [Column(Storage = "_examNum", DbType = "Decimal(18,0)")]
        public decimal ExamNum
        {
            get
            {
                return this._examNum;
            }
            set
            {
                if ((this._examNum != value))
                {
                    if (this._ExamPaper.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.SendPropertyChanging("ExamNum");
                    this._examNum = value;
                    this.SendPropertyChanged("ExamNum",value);
                }
            }
        }

        [Column(Storage = "_txName", DbType = "VarChar(30) NOT NULL", CanBeNull = false)]
        public string TXName
        {
            get
            {
                return this._txName;
            }
            set
            {
                if ((this._txName != value))
                {
                    this.SendPropertyChanging("TXName");
                    this._txName = value;
                    this.SendPropertyChanged("TXName",value);
                }
            }
        }

        [Column(Storage = "_tl", DbType = "Int")]
        public int TL
        {
            get
            {
                return this._tl;
            }
            set
            {
                if ((this._tl != value))
                {
                    this.SendPropertyChanging("TL");
                    this._tl = value;
                    this.SendPropertyChanged("TL",value);
                }
            }
        }

        [Column(Storage = "_singleScore", DbType = "Real")]
        public float SingleScore
        {
            get
            {
                return this._singleScore;
            }
            set
            {
                if ((this._singleScore != value))
                {
                    this.SendPropertyChanging("SingleScore");
                    this._singleScore = value;
                    this.SendPropertyChanged("SingleScore",value);
                }
            }
        }

        [Column(Storage = "_fullScore", DbType = "Real")]
        public float FullScore
        {
            get
            {
                return this._fullScore;
            }
            set
            {
                if ((this._fullScore != value))
                {
                    this.SendPropertyChanging("FullScore");
                    this._fullScore = value;
                    this.SendPropertyChanged("FullScore",value);
                }
            }
        }

        [Column(Storage = "_bz", DbType = "VarChar(500)")]
        public string BZ
        {
            get
            {
                return this._bz;
            }
            set
            {
                if ((this._bz != value))
                {
                    this.SendPropertyChanging("BZ");
                    this._bz = value;
                    this.SendPropertyChanged("BZ",value);
                }
            }
        }

        [Column(Storage = "_timeArea", DbType = "Int")]
        public int TimeArea
        {
            get
            {
                return this._timeArea;
            }
            set
            {
                if ((this._timeArea != value))
                {
                    this.SendPropertyChanging("TimeArea");
                    this._timeArea = value;
                    this.SendPropertyChanged("TimeArea",value);
                }
            }
        }

        [Association(Name = "TX_EnPower", Storage = "_EnPower", ThisKey = "TXNum", OtherKey = "TXNum")]
        public EntitySet<EnPower> EnPower
        {
            get
            {
                return this._EnPower;
            }
            set
            {
                this._EnPower.Assign(value);
            }
        }

        [Association(Name = "TX_STK", Storage = "_STK", ThisKey = "TXNum", OtherKey = "TXNum")]
        public EntitySet<STK> STK
        {
            get
            {
                return this._STK;
            }
            set
            {
                this._STK.Assign(value);
            }
        }

        [Association(Name = "ExamPaper_TX", Storage = "_ExamPaper", ThisKey = "ExamNum", OtherKey = "ExamNum", IsForeignKey = true)]
        public ExamPaper ExamPaper
        {
            get
            {
                return this._ExamPaper.Entity;
            }
            set
            {
                ExamPaper previousValue = this._ExamPaper.Entity;
                if (((previousValue != value)
                            || (this._ExamPaper.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging("ExamPaper");
                    if ((previousValue != null))
                    {
                        this._ExamPaper.Entity = null;
                        previousValue.TX.Remove(this);
                    }
                    this._ExamPaper.Entity = value;
                    if ((value != null))
                    {
                        value.TX.Add(this);
                        this._examNum = value.ExamNum;
                    }
                    else
                    {
                        this._examNum = default(decimal);
                    }
                    this.SendPropertyChanged("ExamPaper",value);
                }
            }
        }

        private void attach_EnPower(EnPower entity)
        {
            entity.TX = this;
        }

        private void detach_EnPower(EnPower entity)
        {
            entity.TX = null;
        }

        private void attach_STK(STK entity)
        {
            entity.TX = this;
        }

        private void detach_STK(STK entity)
        {
            entity.TX = null;
        }
    }
}
